#ifndef G3_TEXTURE_H
#define G3_TEXTURE_H

#include "log.h"

#include "res_handle.h"

#include <string>

#include "types.h"
#include "tex/tex_bitmap.h"
#include "file/f_fstream.h"
#include "tex/tex_png.h"
#include "tex/tex_bmp.h"
#include "tex/tex_jpeg.h"
#include "tex/tex_dds.h"
#include "file/f_filehandler.h"
#include "file/f_absfs.h"

namespace G3 {

using std::string;

enum TEXTURE_FILTER {
	GTF_NEAREST = 0,
	GTF_LINEAR = 1,
	GTF_MIPMAP = 2
};

class TEXTURE: public RESOURCE_BASE {
	public:
		TEXTURE ();
		~TEXTURE ();

		int ID;
		std::string Name;

		TEXTURE_FILTER Filter;

		bool BitmapLocked;
		boost::shared_ptr<BITMAP> Bitmap;
		LOG *Log;

		TEXTURE& operator=(const TEXTURE &t);

//==============================================================================
// Loads an image
//==============================================================================
		bool LoadImage (STREAM *Stream, const std::string &filename);
		bool LoadImage (const std::string &aFilename);

//==============================================================================
// Sets OpenGL texture filter
//==============================================================================
		bool glFilter (TEXTURE_FILTER aFilter);

//==============================================================================
// Builds an OpenGL texture from the Bitmap
//==============================================================================
		int glBuild2D (TEXTURE_FILTER aFilter);

//==============================================================================
// Releases the texture
//==============================================================================
		void Release ();

		void ReleaseBitmap ();

		void ReleaseFromCard ();

//==============================================================================
// Reloads the texture
//==============================================================================
		bool Recreate ();

//==============================================================================
// Gets the approximate size of the texture when loaded
//==============================================================================
		long GetSize ();

//==============================================================================
// Gets the texture dimensions
//==============================================================================
		dword GetWidth ();
		dword GetHeight ();

//==============================================================================
// Gets the texture flags
//==============================================================================
		byte GetFlags ();

//==============================================================================
// Clears everything
//==============================================================================
		void Clear ();
};

typedef G3::HANDLE<G3::TEXTURE> H_TEXTURE;

}

#endif //G3_TEXTURE_H

